from flask import Flask, render_template, redirect, url_for
from flask_wtf import FlaskForm
from wtforms import StringField, EmailField, SubmitField
from wtforms.validators import DataRequired, Email

app = Flask(__name__)
app.secret_key = 'your_secret_key'  # Required for form protection

class MyForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])
    email = EmailField('Email', validators=[DataRequired(), Email()])
    submit = SubmitField('Submit')


# class MyForm(FlaskForm):
#     name = StringField('Name', validators=[
#         DataRequired(), Length(min=1, max=50)
#     ])
#     email = EmailField('Email', validators=[
#         DataRequired(), Email()
#     ])
#     submit = SubmitField('Submit')


@app.route('/', methods=['GET', 'POST'])
def form():
    form = MyForm()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        return f'Name: {name}, Email: {email}'
    return render_template('form1.html', form=form)

if __name__ == '__main__':
    app.run(debug=True)